//#include<stdio.h>
//int int_cmp(const void* p1, const void* p2)
//{
//	return (*(int*)p1) - (*(int*)p2);
//}
//int main()
//{
//	int arr[10] = { 10,9,8,7,6,5,4,3,2,1 };
//	int i = 0;
//	qsort(arr, sizeof(arr) / sizeof(arr[0]), sizeof(arr[0]), int_cmp);
//	for (i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
//	{
//		printf("%-2d", arr[i]);
//	}
//	return 0;
//}
//#include<stdio.h>
//#include<string.h>
//struct student
//{
//	char name[20];
//	int age[20];
//};
//int cmp_name(const void* p1, const void* p2)
//{
//	//return (*(char*)p1) - (*(char*)p2);
//	return strcmp(((struct student*)p1)->name, ((struct student*)p2)->name);
//}
// void test_name()
//{
//	 struct student s1[3] = { {"zhangsan",20},{"lisi",25} ,{"wangwu",29} };
//	 qsort(s1, sizeof(s1) / sizeof(s1[0]), sizeof(s1[0]), cmp_name);
//	 struct student* p = s1;
//	 for (p = s1; p < &s1[3]; p++)
//	 {
//		 printf("%s ", (*p).name, (*p).age);
//	 }
//	 printf("\n");
//	
//}
// void test_age()
// {
//	 struct student s1[3] = { {"zhangsan",20},{"lisi",25} ,{"wangwu",29} };
//	 qsort(s1, sizeof(s1) / sizeof(s1[0]), sizeof(s1[0]), cmp_age);
//	 struct student* p = s1;
//	 for (p = s1; p < &s1[3]; p++)
//	 {
//		 printf("%d", (*p).age);
//	 }
//int main()
//{
//	
//	test_name();
//	test_age();
//	return 0;
//}
#include<stdio.h>
void exchange(const void* p1, const void* p2, int width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = *((char*)p1 + i);
		*((char*)p1 + i) = *((char*)p2 + i);
		*((char*)p2 + i) = tmp;
	}
}
	
int get_comp(const void* p1, const void* p2)
{
	return (*(int*)p1) - *(int*)p2;
}
void bubble(void *base, int size, int width,int(*comp)(void*,void*))
{
	int i = 0;
	int j = 0;
	for ( i = 0; i < size; i++)
	{
		for (j = 0; j < size - 1 - i; j++)
		{
			if (get_comp((char*)base+j*width,(char*)base+(j+1)*width))
			{
				exchange((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}
int main()
{
	int arr[] = { 10,9,8,7,6,5,4,3,2,1 };
	bubble(arr, sizeof(arr) / sizeof(arr[0]), sizeof(arr[0]), get_comp);
	for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		printf("%-2d ", arr[i]);
	}
	printf("\n");
	return 0;
}